package com.oyjd.soft;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class DownSoft2 {
	public static String outPath = "J:/temp/";
	public static boolean clearFlag = false;

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		System.out.println("*****************程序启动*****************");
		if (args.length > 0) {
			for (String s : args) {
				System.out.println("---->main para--->" + s);
			}
			outPath = args[0];
			clearFlag = Boolean.parseBoolean(args[1]);
		}
		Locale.setDefault(new Locale("zh", "CN"));
		if (clearFlag) {
			Conn.clearTemp();

			System.out.println("==========>第一步：获取原始链接");
			List<String> gameUrls = NetDeal.getLink(true);
			List<String> appUrls = NetDeal.getLink(false);
			System.out.println("---------->保存原始链接");
			Conn.insertLink(gameUrls, "1");
			Conn.insertLink(appUrls, "2");
		}

		System.out.println("==========>第二步：下载内容，并更新");
		List<SoftVO> softList = Conn.getSoftList(null);
		for (SoftVO vo : softList) {
			if (NetDeal.doOneSoft(vo)) {
				Conn.updateSoftContent(vo);
			}
		}

		System.out.println("==========>第三步：下载资源");
		List<SoftVO> softList2 = Conn.getSoftList(null);
		for (SoftVO vo : softList2) {
			NetDeal.doDownSoft(vo, outPath);
		}

		System.out.println("==========>第四步：比较标记历史数据");
		Conn.compareSoft();

		System.out.println("==========>第五步：插入新APK");
		List<SoftVO> tmp = Conn.getSoftList(null);
		List<SoftVO> tmpGame = Conn.getSoftList("1");
		List<SoftVO> tmpApp = Conn.getSoftList("2");

		List<SoftVO> leftGame = Conn.getGameSoftListLeft();
		List<SoftVO> leftApp = Conn.getAppSoftListLeft();
		Conn.insertApk(tmp, outPath);

		System.out.println("==========>第六步：插入精品推荐APK");
		List<SoftVO> a = new ArrayList<SoftVO>();
		for (int i = 0; i < 10; i++) {
			a.add(tmpGame.get(i));
			a.add(tmpApp.get(i));
		}
		Conn.insertSort(a, "Soft_BoutiqueForFirstPage");
		Conn.insertSort(a, "Soft_Boutique");

		System.out.println("==========>第七步：插入Soft_All");
		List<SoftVO> b = new ArrayList<SoftVO>();
		b.addAll(tmp);
		b.addAll(leftGame);
		b.addAll(leftApp);
		Conn.insertSort(b, "Soft_All");

		System.out.println("==========>第八步：插入Soft_Game");
		List<SoftVO> c = new ArrayList<SoftVO>();
		c.addAll(tmpGame);
		c.addAll(leftGame);
		Conn.insertSort(c, "Soft_Game");

		System.out.println("==========>第九步：插入Soft_App");
		List<SoftVO> d = new ArrayList<SoftVO>();
		d.addAll(tmpApp);
		d.addAll(leftApp);
		Conn.insertSort(d, "Soft_App");

		System.out.println("*****************程序结束*****************");
		System.exit(0);
	}

}
